from django.shortcuts import render

# Create your views here.
from rest_framework.response import Response
from rest_framework.views import APIView
from apps.users.models import User
from rest_framework.generics import CreateAPIView
from .serializer import RegisterCreateSerializer

class RegisterUsernameAPIView(APIView):
    """
    用户注册
    """
    # 判断用户是否注册过，拿到数据查询数据库
    def get(self,request,username):
        # 获取参数
        count=User.objects.filter(username=username).count()
        # 组织数据
        context ={
            'username':username,
            'count':count
        }
        # 返回数据
        return Response(context)

class RegisterPhoneAPIView(APIView):
    """
    手机号
    """
    # "判断手机号是否注册"
    def get(self,request,mobile):
        # 获取数据
        count = User.objects.filter(mobile = mobile).count()
        # 组织数据
        context = {
            "phon":mobile,
            'count':count,
        }
        # 返回数据
        return Response(context)

class CreateUserView(CreateAPIView):
    """
    post

    用户注册我们需要对数据进行校验，同时需要入库
    """
    serializer_class = RegisterCreateSerializer